//
//  SKUDetailPriceListV.m
//  ZITHER
//
//  Created by weixin on 2019/1/8.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "SKUDetailPriceListV.h"

#import "CurrencyConverterView.h"

@implementation SKUDetailPriceListV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
//        self.backgroundColor = [UIColor redColor];
        
        [self setUI];
        
        [self masonry];

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
        
        [[tap rac_gestureSignal]subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            CurrencyConverterView *cc = [[CurrencyConverterView alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH)];
            cc.model = self.model;
            [cc show];
        }];
        
    }
    return self;
}

-(void)setModel:(skuDetailModel *)model{
    _model = model;
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    int priceInt = [self.model.price intValue];
    NSString *price1 = @"";
    NSString *price2 = @"";

    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price1= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price1 = @"暂无";
    }
    priceInt = [self.model.priceMax intValue];

    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price2= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price2 = @"暂无";
    }
    
    self.secondHandPrice.text = [NSString stringWithFormat:@"￥%@ - ￥%@",price1,price2]; //二手价

}

-(void)masonry{
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.left.equalTo(self.lab.mas_right).offset(5);
        make.width.height.mas_equalTo(15);
    }];
    
    [self.lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.left.equalTo(self).offset(15);
        make.height.mas_equalTo(15);
    }];
    
    [self.iconBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(0);
        make.right.equalTo(self).offset(-15);
        make.width.mas_equalTo(5);
        make.height.mas_equalTo(11);
    }];
    
    
    BaseLab * secondHandPrice = [[BaseLab alloc]initializeFrame:CGRectMake(40, 15, 50, 15) text:@"二手参考价" font:10 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
    //    secondHandPrice.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
    secondHandPrice.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:15];
    secondHandPrice.textColor = baseColorTheme;
    [self addSubview:secondHandPrice];
    
    [secondHandPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lab.mas_bottom).offset(44);
        //        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(15);
        make.height.mas_equalTo(16);
    }];
    
    [self.secondHandPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondHandPrice.mas_bottom).offset(8);
        make.left.equalTo(self).offset(15);
        make.height.mas_equalTo(16);
    }];
    
}


-(void)setUI{
    
    [self addSubview:self.icon];
    [self addSubview:self.iconBack];
    [self addSubview:self.lab];
    [self addSubview:self.secondHandPrice];
    
}


- (BaseImageV *)icon{
    if (!_icon) {
        _icon = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 0, 0) contentMode:2];
        [_icon setCornerRadiusWithRadius:7.5 isMasks:YES];
        _icon.image = [UIImage imageNamed:@"zhongguo"];
    }
    return _icon;
}


-(BaseImageV *)iconBack{
    if (!_iconBack) {
        _iconBack = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 0, 0) contentMode:2];
        _iconBack.image = [UIImage imageNamed:@"sku_btn_into"];
//        [_iconBack sd_setImageFlags:@"sku_btn_into"];
    }
    return _iconBack;
}


-(BaseLab *)lab{
    if (!_lab) {
        _lab = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"大陆公价" font:10 textColor:[UIColor colorWithHex:@"333333"] isBold:NO numberOfLines:1];
        _lab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
    }
    return _lab;
}



-(BaseLab *)secondHandPrice{
    if (!_secondHandPrice) {
        _secondHandPrice = [[BaseLab alloc]initializeFrame:CGRectMake(90, 15, 100, 14) text:@"💰250，200" font:10 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        //        _secondHandPrice.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:20];
        _secondHandPrice.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:15];
        
        _secondHandPrice.textColor = baseColorTheme;
    }
    return _secondHandPrice;
}



@end
